package com.ruoyi.app.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.app.annotation.AppSecurity;
import com.ruoyi.app.domain.DictData;
import com.ruoyi.app.util.ReqMsg;
import com.ruoyi.app.util.RspMsg;
import com.ruoyi.business.service.IAwardDistributionService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * 分销层级
 *
 * @author cyh
 * @date 2022/6/23 5:41 下午
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/activity")
public class ActivityController extends BaseController {

    private IAwardDistributionService awardDistributionService;

    @GetMapping("/detail")
    @Log(title = "获取活动详细", businessType = BusinessType.GET)
    public RspMsg getActivityDetail() {
        return RspMsg.ok(awardDistributionService.getUserActivityDetail());
    }

    @GetMapping("/award/flow")
    @Log(title = "获取奖励记录流水", businessType = BusinessType.GET)
    public RspMsg getAwardFlow() {
        return RspMsg.ok(awardDistributionService.getAwardRecord(appService.webGetUserId()));
    }


    @GetMapping("/award/invite/flow")
    @Log(title = "获取奖励邀请记录流水", businessType = BusinessType.GET)
    public RspMsg getAwardInviteFlow() {
        return RspMsg.ok(awardDistributionService.getAwardInviteFlow(appService.webGetUserId()));
    }

    @GetMapping("/dict/{type}")
    @Log(title = "H5数据字典", businessType = BusinessType.GET)
    public RspMsg commonDict(@PathVariable String type) {
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType(type);
        sysDictData.setStatus("0");
        List<SysDictData> sysDictDataList = sysDictDataService.selectDictDataList(sysDictData);
        List<DictData> dictDataList = new ArrayList<>();
        sysDictDataList.stream().forEach(p -> dictDataList.add(DictData.builder().label(p.getDictLabel()).value(p.getDictValue()).sort(p.getDictSort()).build()));
        JSONObject result = new JSONObject();
        result.put("dicData", dictDataList);
        return RspMsg.RspMsgOk(result);
    }

}
